/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cc.model;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author gianmariospacagna
 */
@Entity
@Table(name = "RATE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Rate.findAll", query = "SELECT r FROM Rate r"),
    @NamedQuery(name = "Rate.findByCurrencyfrom", query = "SELECT r FROM Rate r WHERE r.ratePK.currencyfrom = :currencyfrom"),
    @NamedQuery(name = "Rate.findByCurrencyto", query = "SELECT r FROM Rate r WHERE r.ratePK.currencyto = :currencyto"),
    @NamedQuery(name = "Rate.findByRate", query = "SELECT r FROM Rate r WHERE r.rate = :rate")})
public class Rate implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected RatePK ratePK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "RATE")
    private float rate;

    public Rate() {
    }

    public Rate(RatePK ratePK) {
        this.ratePK = ratePK;
    }

    public Rate(RatePK ratePK, float rate) {
        this.ratePK = ratePK;
        this.rate = rate;
    }

    public Rate(String currencyfrom, String currencyto) {
        this.ratePK = new RatePK(currencyfrom, currencyto);
    }

    public RatePK getRatePK() {
        return ratePK;
    }

    public void setRatePK(RatePK ratePK) {
        this.ratePK = ratePK;
    }

    public float getRate() {
        return rate;
    }

    public void setRate(float rate) {
        this.rate = rate;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (ratePK != null ? ratePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Rate)) {
            return false;
        }
        Rate other = (Rate) object;
        if ((this.ratePK == null && other.ratePK != null) || (this.ratePK != null && !this.ratePK.equals(other.ratePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cc.model.Rate[ ratePK=" + ratePK + " ]";
    }
    
}
